<template>
  <div>
      <h1>首页</h1>
      <div v-for="i in list" :key="i.id">
          标题:<br>
          <router-link :to="{'path':'/index2','query':{'id':i.id}}">
          {{i.title}}
          </router-link>
      </div>
      <div>
          <input type="button" value="上一页" @click="show(cur_num-1)">
          <input type="button" v-for="num in num_list" :key="num" :value="num" @click="show(num)">
          <input type="button" value="下一页" @click="show(cur_num+1)">
      </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            list:[],
            num_list:[],
            cur_num:1

        }
    },
    created() {
        this.show(1)
    },
    methods: {
        show(num){
            this.cur_num = num
            axios.get('/api/show?num='+num).then(resp=>{
                console.log(resp)
                this.list = resp.data.data
                this.num_list = resp.data.num
            }).catch(error=>{
                console.log(error)
            })
        }
    },
}
</script>

<style>

</style>